package org.zero.orika.converter;

import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.converter.BidirectionalConverter;
import ma.glasnost.orika.metadata.Type;
import org.zero.model.dto.AccountDTO;
import org.zero.model.po.AccountPO;
import org.zero.orika.mapper.AccountMapper;

import java.math.BigDecimal;

/**
 * @author Zero (cnzeropro@qq.com)
 * @date 2021/9/1 15:45
 */
public class AccountConverter extends BidirectionalConverter<Long, AccountDTO> {

    @Override
    public AccountDTO convertTo(Long source, Type<AccountDTO> destinationType, MappingContext mappingContext) {
        // 模拟数据库查询获取信息
        AccountPO accountDO = AccountPO.builder()
                .id(source)
                .balance(new BigDecimal("5645.6565"))
                .name("小小明")
                .password("v4ga24")
                .status((byte) 1)
                .build();
        return new AccountMapper().map(accountDO, AccountDTO.class);
    }

    @Override
    public Long convertFrom(AccountDTO source, Type<Long> destinationType, MappingContext mappingContext) {
        return source.getId();
    }
}
